<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="/sinopac-fn" prefix="fn" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/sinopac/form/CSS/tabs.css">
<script type="text/javascript" src="/sinopac/js/jQuery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/sinopac/js/jQuery/jquery_DOMWindow.js"></script>
<script type="text/javascript" src="/sinopac/js/tools/formUtil.js"></script>

<script>
	function chkApply(){
		var form = $('#form1');
		var voValue = true;
		form.prop('action', '${fn:url('/TokenManagement/index.action')}');
		form.append('<input type="hidden" name="pdfFlag" value="'+voValue+'" />');
		form.submit();
	}

	

	function add(){
		$.openDOMWindow({ 
	    	windowSourceID: '#customerID',
	        height:110,  
	        width:370, 
	        overlay:1, 
	        overlayColor: '#A9A9A9',
	        windowPadding:20,
	        modal:1,
	        borderColor:'steelblue',
	        borderSize:'3', 
	        positionLeft:120, 
	        positionTop:-150,
	    });
	}
	
	
	function getCustId(){
		var custId = $.joinId('#custId01_a','#custId02_a','#custId03_a');
		$('#c').val(custId);
		$('#form2').submit();
	}
	
	$(document).ready(function(){
	//	if(<s:property value="tokenVO.token_esn"/>=='00'){
	//		$('#tokenTd p').css('color : red');
	//	}
		//$('.tokenBtn').hide();
		var voValue = $('#tokenTd').attr('voValue');
		var voValue1 = $('#tokenTd').attr('voValue1');
		switch(voValue){
			case '00':
				if(voValue1 == ''){
					$("#enableToken,#pauseToken,#unstallToken,#invalidToken").addClass('gray');
				}else{
					$("#pauseToken,#unstallToken,#invalidToken").addClass('gray');
				}
				break;
			case '01':
				$("#enableToken,#unstallToken").addClass('gray');
				break;
			case '02':
				$("#enableToken,#pauseToken").addClass('gray');
				break;
			case '03':
			case '04':
				$("#enableToken,#pauseToken,#unstallToken,#invalidToken").addClass('gray');
				break;
			case '05':
				$("#enableToken,#pauseToken,#unstallToken,#invalidToken").addClass('gray');
				break;
		}
		
		if(<s:property value="errorFlag"/>){
			$.openDOMWindow({ 
		    	windowSourceID: '#error',
		        height:110,  
		        width:370, 
		        overlay:1, 
		        overlayColor: '#A9A9A9',
		        windowPadding:20,
		        modal:1,
		        borderColor:'steelblue',
		        borderSize:'3', 
		        positionLeft:120, 
		        positionTop:-150
		    });
		}
		
		$('.tokenBtn').click(function(){
			var self = $(this);
			if(self.hasClass('gray'))
				return;
			var action = self.attr('id');
			var form = $('#confirmForm');
			form.prop('action','/sinopac/TokenManagement/transactionToken');
			if(action == 'pauseToken'){
				$('input[name=actionName]').val(action);
				$('#action').text('暫禁');
			}else if(action == 'unstallToken'){
				$('input[name=actionName]').val(action);
				$('#action').text('解禁');
			}else if(action == 'invalidToken'){
				$('input[name=actionName]').val(action);
				$('#action').text('註銷');
			}else if(action=='enableToken'){
				$('input[name=actionName]').val(action);
				$('#action').text('啟用');
			}
			$.openDOMWindow({ 
		    	windowSourceID: '#confirm',
		        height:110,  
		        width:370, 
		        overlay:1, 
		        overlayColor: '#A9A9A9',
		        windowPadding:20,
		        modal:1,
		        borderColor:'steelblue',
		        borderSize:'3', 
		        positionLeft:120, 
		        positionTop:-150,
		    });
		});
		
		$('.custClass').click(function(){
			var self = $(this);
			var voValue = self.attr('voValue');
			var form = $('#form1');
			form.prop('action', '${fn:url('/Index/chkCustId.action')}');
			form.append('<input type="hidden" name="function_num" value="2" />');
			form.append('<input type="hidden" name="custId" value="'+voValue+'" />');
			form.submit();
		});
		
		if(<s:property value="pdfFlag"/>){
			window.open('/sinopac/form/CustomerApply/viewPDF.jsp?path=' + $('#pdfPath').val());
		}
	});
</script>
<style type="text/css">
a:link, a:visited {
	color: #22f
}

a.gray:link, a.gray:visited {
	color: gray;
	text-decoration : none;
}
</style>
<title>TOKEN一覽</title>
</head>
<body>
	<div id="error" style="display: none;">
		<s:form id="errorForm">
			<table align="center">
				<tr>
					<td>客戶ID <font color="red"><s:property value="#session.customer_id"/></font> <s:property value="errorMessage"/></td>
				</tr>
				<tr>
					<td> 請確認異動的TOKEN ESN為 <font color="red"><s:property value="#session.token_esn"/></font></td>
				</tr>
				<tr>
					<td><input type="button" value="確定" class="closeDOMWindow"/></td>
				</tr>
			</table>			
		</s:form>
	</div>
	<div id="confirm" style="display: none;">
		<s:form id="confirmForm">
			<input type="hidden" name="actionName"/>
			<table align="center">
				<tr>
					<td>請確認執行 <font color="red"><span id="action"></span></font> 作業</td>
				</tr>
				<tr>
					<td> 請確認異動的TOKEN ESN為 <font color="red"><s:property value="#session.token_esn"/></font></td>
				</tr>
				<tr>
					<td><s:submit theme="simple" value="確定"></s:submit></td>
					<td><s:submit theme="simple" cssClass="closeDOMWindow" value="取消"></s:submit></td>
				</tr>
			</table>			
		</s:form>
	</div>
	<div id="customerID" class="idDiv" style="display:none">
			<s:form action="allotmentToken" id="form2">
				<table align="center">
					<tr align="left">
						<td align="left"><s:label value="請輸入客戶ID" theme="simple"/></td>
						<td align="left"><s:textfield name="custId01" id="custId01_a" theme="simple" maxlength="18" size="18"/></td>
						<td>-</td>
						<td align="left"><s:textfield name="custId02" id="custId02_a" theme="simple" maxlength="1" size="1"/></td>
						<td>-</td>
						<td align="left"><s:textfield name="custId03" id="custId03_a" theme="simple" maxlength="2" size="2"/></td>
						<td><s:hidden name="custId" id="c"></s:hidden></td>
					</tr>
					<tr height="50"></tr>
					<tr>
						<td><input type="button" onclick="getCustId()" value="確定"/></td>
						<td><s:submit value="取消" id="btnNo" cssClass="closeDOMWindow" theme="simple"/></td>			
					</tr>	
				</table>
			</s:form>
		</div>
	<s:form id="form1">
		<%@ include file="/form/include/title.jsp" %>
		<table class="table-style"  align="center">
			<tr>
				<th>TOKEN ESN</th>
				<th>TOKEN狀態</th>
				<th>狀態異動</th>
				<th>上次列印領據日期</th>
				<th>領據</th>
				<th>最近異動日</th>
				<th nowrap="nowrap">最近異動經辦</th>
			</tr>
			<tr>
				<td><s:property value="tokenVO.token_esn"/></td>
				<td><s:property value="tokenVO.token_cn"/></td>
				<td id="tokenTd" width="150" voValue="${tokenVO.token_status}" voValue1="${tokenVO.related_to}">
					<s:a id="enableToken" cssClass="tokenBtn" href="#">啟用</s:a>
					<s:a id="pauseToken" cssClass="tokenBtn" href="#">暫禁</s:a>
					<s:a id="unstallToken" cssClass="tokenBtn" href="#">解禁</s:a>
					<s:a id="invalidToken" cssClass="tokenBtn" href="#">註銷</s:a>
				</td>
				<td><s:property value="tokenVO.receipt_printed_time"/></td>
				<s:if test='tokenVO.receipt_printed_time==""'>
					<td>&nbsp;</td>
				</s:if>
				<s:else>
					<td><a onclick="chkApply()" href="#">列印</a></td>					
				</s:else>
				<td><a href="#"><s:property value="tokenVO.updated_time"/></a></td>
				<td><s:property value="tokenVO.operator"/></td>
			</tr>
		</table>
		<table align="center">
			<tr align="center">
				<td style="font-size: 16px">TOKEN ESN <font color="red"><s:property value="tokenVO.token_esn"/></font> 已配發至以下客戶:  <s:if test='tokenVO.token_status=="00" && tokenVO.related_to == null'><a onclick="add()" href="#">新增</a></s:if></td>
			</tr>
		</table>
		<table class="table-style" align="center">
			<tr>
				<th>集團戶</th>
				<th>客戶ID</th>
				<th>客戶名稱</th>
				<th>AO Code</th>
				<th>OTP狀態</th>
				<th>最近異動日</th>
				<th nowrap="nowrap">最近異動經辦</th>
			</tr>
			<s:if test="tokenVO.custVO.size()>0">
				<s:iterator value="tokenVO.custVO">
					<tr>
						<td><s:property value="group_cn"/></td>
						<td><a class="custClass" href="#" voValue="${customer_id}"><s:property value="customer_id"/></a></td>
						<td><s:property value="customer_name"/></td>
						<td><s:property value="ao_code"/></td>
						<td><s:property value="otp_status"/></td>
						<td><a><s:property value="updated_time"/></a></td>
						<td><s:property value="#session.userName"/></td>
					</tr>
				</s:iterator>
			</s:if>
		</table>
	</s:form>
	<input type="hidden" id="pdfPath" name="pdfPath" value="${pdfPath}" />
</body>
</html>